//
//  RouteViewController.swift
//  BaseSwift
//
//  Created by gh on 2019/10/14.
//  Copyright © 2019 ghwang. All rights reserved.
//

import UIKit
import PYSearch
import JXPhotoBrowser
import EasyNavigation
import WebKit

class RouteViewController: UIViewController {

    private var lastMenuBtn:UIButton?
    private var coord:CLLocationCoordinate2D?
    private var mapview:MKMapView?
    private var currintTag = 0
    private var currentArr:Array<LSListAnnotation> = Array()
    private var currentID:String = ""
    private var titsLine:Array<String> = Array()
    private var lastTitLab:UIButton?
    private var detailView:UIView = UIView()
    private var categorys:Array<CategoryVo> = Array()
    private var curSubCardArr:Array<RouteInfoVo> = Array()
    private var mPage = 1
    private var allPage = 0
    
    var pullBtn: UIButton?
    
    var backToUserClick = false
    var isMenuLoadAll = false

    
    private var isDayBtnClick = false
    
    var curCategory:CategoryVo?
    var curDetailCategory:CategoryVo?
    var ccLine: MKPolyline?
    
    var page = 1
    var isHaveMore = true

    var openBtn:UIButton?

    var keywords:String = ""
    
    var isOnlyOne = false
    
    var curPage = 0
    var points:Array<CLLocationCoordinate2D> = Array()

    var firstMod:RouteInfoVo?
    
    var curMod:RouteInfoVo?
    var isFirstIn = true

    var pageMenu: SPPageMenu?
    
    var isRemoveTitleScrollView = false

    
    let commentbg = UIView()
    let inputV = GCPlaceholderTextView()
    var scrMenuBg: UIScrollView?
    
    
    var bg = UIScrollView()
    var bbg = UIView()
    var titScrView:UIScrollView?
    let bline = UIView()
    var isSlience = false

    func getActivisGoods() -> Array<ActivisProduct>{
        
        if SPUtil.init().activits == nil {
            
            return []
        }
        
        let list: [ActivisProduct] = [ActivisProduct].deserialize(from:SPUtil.init().activits)! as! [ActivisProduct]
        return list
    }

     lazy var commentBottomView:UIView = {
         
         let bg = UIView()
         bg.backgroundColor = UIColor.white
         
         let commBtnBg = UIButton()
         commBtnBg.sd_cornerRadius = 16
         bg.addSubview(commBtnBg)
         commBtnBg.addTarget(self, action: #selector(showCommentAlert), for: .touchUpInside)
         commBtnBg.backgroundColor = UIColor.backgroundColor
         let _ = commBtnBg.sd_layout()?.widthIs(168)!.heightIs(32)!.leftSpaceToView(bg,16)?.centerYEqualToView(bg)
         let icon = UIImageView()
         icon.image = UIImage(named: "写评论")
         commBtnBg.addSubview(icon)
         let _ = icon.sd_layout()?.widthIs(14)!.heightIs(13)?.centerYEqualToView(commBtnBg)!.leftSpaceToView(commBtnBg,16)
         
         let lab = UILabel()
         lab.font = UIFont.commonFontSmaller
         lab.textColor = UIColor.tabbarDefaultTextColor
         lab.text = "说点啥..."
         commBtnBg.addSubview(lab)
         let _ = lab.sd_layout()?.leftSpaceToView(icon,10)!.heightIs(20)!.centerYEqualToView(commBtnBg)!.widthIs(75)
         
         let shareBtn = UIButton()
         shareBtn.addTarget(self, action: #selector(shareClick), for: .touchUpInside)
         shareBtn.setImage(UIImage(named: "分享"), for: .normal)
         bg.addSubview(shareBtn)
         let _ = shareBtn.sd_layout()?.rightSpaceToView(bg,16)!.centerYEqualToView(bg)!.widthIs(23)!.heightIs(22)
         
         
         
         
         let commentBtn = UIButton()
         commentBtn.addTarget(self, action: #selector(lookZixun), for: .touchUpInside)
         commentBtn.setImage(UIImage(named: "评论"), for: .normal)
         commentBtn.titleLabel?.font = UIFont.smallerLessthanFont
         commentBtn.setTitleColor(UIColor.textPlaceHolderColor, for: .normal)
         bg.addSubview(commentBtn)
         let _ = commentBtn.sd_layout()?.rightSpaceToView(shareBtn,16)!.centerYEqualToView(bg)!.widthIs(23)!.heightIs(22)

         
         
         let favBtn = UIButton()
         favBtn.addTarget(self, action: #selector(favBtnClick), for: .touchUpInside)
          favBtn.setImage(UIImage(named: "收藏"), for: .normal)
         favBtn.setImage(UIImage(named: "faved"), for: .selected)

          favBtn.titleLabel?.font = UIFont.smallerLessthanFont
          favBtn.setTitleColor(UIColor.textPlaceHolderColor, for: .normal)
          favBtn.setTitle("18", for: .normal)
          bg.addSubview(favBtn)
          let _ = favBtn.sd_layout()?.rightSpaceToView(commentBtn,16)!.centerYEqualToView(bg)!.widthIs(23)!.heightIs(22)

         return bg
         
     }()

    lazy var slideMenuView: UIView = {
        
        let bg = UIView()
        bg.backgroundColor = UIColor.white
        bg.frame = CGRect(x: KScreenWidth-225, y: self.view.height-HT_TabbarSafeBottomMargin-210, width: 225, height: 40)
        bg.SetMutiBorderRoundingCornersTLBL(bg, corner: 20)
        
        let sbg = UIView()
        bg.addSubview(sbg)
        sbg.backgroundColor = UIColor.white
        sbg.sd_layout()?.spaceToSuperViewIs(UIEdgeInsets(top: 2, left: 0, bottom: 2, right: 0))
        sbg.updateLayout()
        sbg.SetMutiBorderRoundingCornersTLBL(bg, corner: 20)
        
        let icon1 = UIImage(named: "关闭")
        let icon2 = UIImage(named: "收藏")
        let icon3 = UIImage(named: "评论")
        let icon4 = UIImage(named: "分享")
        let icon5 = UIImage(named: "更多")
        var icons = Array<UIImage>()
        icons.append(icon1!)
        icons.append(icon2!)
        icons.append(icon3!)
        icons.append(icon4!)
        icons.append(icon5!)

        for index in 0 ..< icons.count{
            
            let btn = UIButton()
            btn.tag = 10086+index
            sbg.addSubview(btn)
            btn.setImage(icons[index], for: .normal)
            btn.frame = CGRect(x: index*45, y: 0, width: 45, height: 38)
            if index == 0{
                
                btn.addTarget(self, action: #selector(openOrClose), for: .touchUpInside)
                self.openBtn = btn

            }else{
                
                btn.addTarget(self, action: #selector(slideMenuClick), for: .touchUpInside)

            }

        }

        return bg
        
    }()
    
    func sendRequestDetail(){
        
                                        
        API.home_category_detail(params: ["projectId":self.curCategory!.id!]) { (result) in
            

        
            let cateDetail  = (result as! CategoryVo)
            self.curDetailCategory = cateDetail

            var arr = cateDetail.routeInfoList!
            

            //change
            
            if arr.count == 0{
                
                
                ToastUtil.show(msg: "暂无线路明细信息")

                //添加活动产品

                for item in self.getActivisGoods(){
                    
                    let tempRouteInfo = RouteInfoVo()
                    tempRouteInfo.isActivity = true
                    tempRouteInfo.longitude = item.longitude
                    tempRouteInfo.latitude = item.latitude
                    tempRouteInfo.imgUrl = item.icon
                    tempRouteInfo.title = item.title
                    tempRouteInfo.address = item.context
                    tempRouteInfo.pdtId = item.pdtId
                    
                    arr.append(tempRouteInfo)
                    
                    
                }
                var anns = Array<RouteInfoVo>()
                arr.forEach { (item) in
                 
                    anns.append(item)

                }
                self.firstMod = nil
                self.showAntions(arr: anns)
                self.view.bringSubviewToFront(self.slideMenuView)
                return
            }
                        
            self.reloadMapCards(arr: arr)

            //添加活动产品

            for item in self.getActivisGoods(){
                
                let tempRouteInfo = RouteInfoVo()
                tempRouteInfo.isActivity = true
                tempRouteInfo.longitude = item.longitude
                tempRouteInfo.latitude = item.latitude
                tempRouteInfo.imgUrl = item.icon
                tempRouteInfo.title = item.title
                tempRouteInfo.address = item.context
                tempRouteInfo.pdtId = item.pdtId
                
                arr.append(tempRouteInfo)
                
                
            }
            var anns = Array<RouteInfoVo>()
            arr.forEach { (item) in
             
                anns.append(item)

            }
            self.firstMod = nil
            self.showAntions(arr: anns)
            self.view.bringSubviewToFront(self.slideMenuView)
            


            //画线
            self.points.removeAll()

            if self.ccLine != nil {
                  
                  self.mapview?.removeOverlay(self.ccLine!)
              }
            for item in cateDetail.routeInfoList!{
                
//                let latlongt = BZHttpFileHelper.baiduToGaode(withLat: Double(item.latitude!)!, longt: Double(item.longitude!)!)
//                let lat = latlongt.split(string: ",").first
//                let longt = latlongt.split(string: ",").last
                
                
                let coordinate = CLLocationCoordinate2D(latitude: Double((item.latitude)!)!, longitude: Double((item.longitude)!)!)
                self.points.append(coordinate)

            }
            self.ccLine = MKPolyline.init(coordinates: self.points, count: self.points.count)
            
            self.mapview?.addOverlay(self.ccLine!, level: .aboveLabels)
            DispatchQueue.main.asyncAfter(deadline: .now()+3, execute:
            {
                
                self.isFirstIn = false

            })

        }
                                        
    }
    
    func sendRequestForSlience(){
        
        API.home_category_list(params: ["startLong":"",
                                        "startLat":"",
                                        "distance":"40000",
                                        "type":"ROUTE",
                                        "keyWord":self.keywords],isSlience:true) { (result) in

                                            
                                    let page = result as! Page<CategoryVo>
                                                                                                                                          
                                     if self.mPage == 1{
                                         
                                         self.categorys = page.list

                                     }else{
                                         
                                         for item in page.list{
                                             
                                             self.categorys.append(item)
                                         }
                                     }
                                            
                                                                     
                                     self.mPage = self.mPage+1
                                     
                                     if self.mPage > self.allPage{
                                        
                                        self.reloadMapMenus(arr: self.categorys)
                                        self.isMenuLoadAll = true


                                     }else{
                                         
                                        self.sendRequestForSlience()
                                     }

        }
    }
    
    func sendRequest(){
        
        API.home_category_list(params: ["startLong":"",
                                        "startLat":"",
                                        "distance":"40000",
                                        "type":"ROUTE",
                                        "keyWord":self.keywords],isSlience:false) { (result) in

                                            
                                    let page = result as! Page<CategoryVo>
                                                                     
                                     self.allPage = page.pages
                                                                     
                                     self.categorys = page.list

                                    if self.categorys.count == 0{
                                        ToastUtil.showAlert(context: self, title: "提示", msg: "未检索到\(self.keywords)相关信息")
                                        
                                        return
                                    }
                                    if self.curCategory == nil{
                                        
                                        self.curCategory = self.categorys.get(at:0)
                                    }

                                    self.reloadMapMenus(arr: self.categorys)
                                    self.sendRequestDetail()
                                    self.sendRequestForSlience()



        }
        
    }
    
    
    override func viewDidLoad() {
        
        
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.navigationView.setTitle("行程路线")
        self.view.backgroundColor = UIColor.backgroundColor

        //map
        self.mapview = MKMapView()
        view.addSubview(self.mapview!)
        self.mapview?.delegate = self
        let _ = self.mapview?.sd_layout()?.spaceToSuperView(UIEdgeInsets(top: 44+HT_StatusBarAndNavigationBarHeight, left: 0, bottom: HT_TabbarSafeBottomMargin+190, right: 0))
        self.mapview?.autoresizingMask = .flexibleHeight
        self.mapview?.showsUserLocation = true
        
        let backUserBtn = UIButton()
        backUserBtn.addTarget(self, action: #selector(backToUser), for: .touchUpInside)
        backUserBtn.setImage(UIImage(named: "定位002"), for: .normal)
        self.mapview?.addSubview(backUserBtn)
        backUserBtn.backgroundColor = UIColor.white
        let _ = backUserBtn.sd_layout()?.widthIs(32)!.heightIs(32)!.leftSpaceToView(self.mapview,8)!.bottomSpaceToView(self.mapview,35)
        backUserBtn.sd_cornerRadius = 16

        
        let backLineBtn = UIButton()
        backLineBtn.addTarget(self, action: #selector(backToLine), for: .touchUpInside)
        backLineBtn.setImage(UIImage(named: "map_line"), for: .normal)
        self.mapview?.addSubview(backLineBtn)
        backLineBtn.backgroundColor = UIColor.white
        let _ = backLineBtn.sd_layout()?.widthIs(32)!.heightIs(32)!.leftSpaceToView(self.mapview,8)!.bottomSpaceToView(backUserBtn,16)
        backLineBtn.sd_cornerRadius = 16



        
        //地图卡片背景；
        bbg = UIView()
        bbg.backgroundColor = UIColor.white
        view.addSubview(bbg)
        bbg.clipsToBounds = true
        view.bringSubviewToFront(bbg)
        let _ = bbg.sd_layout()?.widthRatioToView(view,1)!.heightIs(190+HT_TabbarSafeBottomMargin)!.bottomSpaceToView(view,0)
        bbg.updateLayout()
        bbg.SetMutiBorderRoundingCornersTLTR(bbg, corner: 20)
        bbg.layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.1).cgColor
        bbg.layer.shadowOffset = CGSize(width: 0, height: 0)
        bbg.layer.shadowOpacity = 1
        bbg.layer.shadowRadius = 6
        
        self.view.addSubview(self.slideMenuView)
        self.view.bringSubviewToFront(self.slideMenuView)

        
        if self.isOnlyOne {
            
            self.reloadMapMenus(arr: [self.curCategory!])
            sendRequestDetail()
            
        }else{
            
            self.navigationView.addRightButton(with: UIImage(named: "search_11")) { (view) in
                
                self.startSearch()
                
            }
            sendRequest()
        }

    }
    

    func reloadMapMenus(arr:Array<CategoryVo>){
        
        var tits = Array<String>()
        for item in arr {
            
            tits.append(item.proName!)
        }
        pageMenu = SPPageMenu.init(frame: CGRect(x: 0, y: HT_StatusBarAndNavigationBarHeight, width: KScreenWidth, height: 45), trackerStyle: .nothing)
        pageMenu?.setItems(tits, selectedItemIndex: 0)
        pageMenu?.itemTitleFont = UIFont.commonFontSmall
        pageMenu?.unSelectedItemTitleColor = UIColor.tabbarDefaultTextColor
        pageMenu?.selectedItemTitleColor = UIColor.tabbarDefaultTextColor
        pageMenu?.selectedItemZoomScale = 1.1
        pageMenu?.delegate = self
        pageMenu?.dividingLineHeight = 0
        self.view.addSubview(pageMenu!)

        
    }

    func reloadMapCards(arr:Array<RouteInfoVo>){
                
        
        self.curSubCardArr = arr
        
        for item in self.curSubCardArr{
            
            item.isSelect = false
            
        }
        
        //bbg.removeFromSuperview()

        
        bg.showsHorizontalScrollIndicator = false
        bg.delegate = self
        bbg.addSubview(bg)
        bg.isPagingEnabled = true
        bg.clipsToBounds = false
        bg.backgroundColor = UIColor.white
        bg.contentSize = CGSize(width: CGFloat(arr.count)*bbg.width, height: bg.height)
        let _ = bg.sd_layout()?.spaceToSuperView(UIEdgeInsets(top: 35, left: 20, bottom: HT_TabbarSafeBottomMargin+25, right: 20))
        //bg.frame = CGRect(x: 20, y: 35, width: KScreenWidth-40, height: 135)
        bg.updateLayout()

      

        for views in bg.subviews{

            views.removeFromSuperview()

        }
        
        for index in 0 ..< arr.count{
            
            let mod = arr.get(at: index)
            let cardMask = UIView()
            cardMask.frame = CGRect(x: CGFloat(index)*(bg.width)-15, y:20 , width: bg.width, height: 95)
            
            cardMask.layer.shadowColor = UIColor.lightGray.cgColor
            cardMask.layer.shadowOffset = CGSize(width: 1, height: 5)
            cardMask.layer.shadowOpacity = 0.4

            bg.addSubview(cardMask)
            bg.setupAutoContentSize(withRightView: cardMask, rightMargin: 0)
            
            
            let subBg = UIButton()
            subBg.addTarget(self, action: #selector(cardMaskClick), for: .touchUpInside)
            subBg.tag = 10086+index
            cardMask.addSubview(subBg)
            subBg.backgroundColor = UIColor.white
            subBg.layer.cornerRadius = 8
            subBg.layer.masksToBounds = true
            let _ = subBg.sd_layout()?.leftSpaceToView(cardMask,16)!.rightSpaceToView(cardMask,16)!.topSpaceToView(cardMask,0)!.heightIs(95)
            
            let numLab = UILabel()
            subBg.addSubview(numLab)
            let _ = numLab.sd_layout()?.widthIs(28)!.heightIs(17)!.rightSpaceToView(subBg,5)!.topSpaceToView(subBg,8)
            numLab.textAlignment = .center
            numLab.textColor = UIColor.GP_Orange_Color
            numLab.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight(rawValue: 0.2))
            numLab.text = mod!.stepNum.description
            
            if mod!.isActivity == true{
                
                numLab.isHidden = true
                
            }
            
            
            let photo = MyImgView()
            photo.url = mod?.imgUrl
            photo.isUserInteractionEnabled = true
            let tap = UITapGestureRecognizer(target: self, action: #selector(imgClick))
            tap.numberOfTouchesRequired = 1
            tap.numberOfTapsRequired = 1
            photo.addGestureRecognizer(tap)
            photo.backgroundColor = UIColor.lineColor
            subBg.addSubview(photo)
            let _ = photo.sd_layout()?.widthIs(95)!.heightIs(95)!.leftSpaceToView(subBg,0)!.topSpaceToView(subBg,0)
            
            if mod?.imgUrl?.starts(with: "http") == true {
                
             photo.sd_setImage(with: URL(string:(mod?.imgUrl!)!), placeholderImage: UIImage(named: "holder"), options: .lowPriority) { (A, B, C, D) in

                }
                
            }else{
                
                photo.sd_setImage(with: URL(string:"https://hqctv.oss-cn-beijing.aliyuncs.com/"+(mod?.imgUrl!)!), placeholderImage: UIImage(named: "holder"), options: .lowPriority) { (A, B, C, D) in
                    
                }
                
            }
            

            
            
            let titLab = UILabel()
            titLab.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight(rawValue: 0.2))
            titLab.textColor = UIColor.textTitleColorBlack
            titLab.text = mod?.title?.replacingOccurrences(of: "#", with: " ")
            subBg.addSubview(titLab)
            let _ = titLab.sd_layout()?.leftSpaceToView(photo,16)!.heightIs(20)!.topSpaceToView(subBg,10)!.rightSpaceToView(subBg,16)
            
            let infoLab = UILabel()
            infoLab.font = UIFont.commonFontSmaller
            infoLab.textColor = UIColor.textPlaceHolderColor
            infoLab.text = mod?.address
            subBg.addSubview(infoLab)
            let _ = infoLab.sd_layout()?.leftSpaceToView(photo,16)!.heightIs(20)!.topSpaceToView(titLab,10)!.rightSpaceToView(subBg,16)
            
            let tags = mod?.tag?.split(string: ",")
            
            var tagss = Array<String>()
            tagss = tags!
            if (tags?.count)! >= 3 {
                
                tagss.remove(at: tags!.count-1)
                tagss.remove(at: tags!.count-2)
                tagss.remove(at: tags!.count-3)

            }else{
                
                tagss = tags!
            }
            
            if tagss.count > 0{
                
                infoLab.updateLayout()
                let tagsView = STTagsView.tagView(withFrame: CGRect(x: 16+95, y: infoLab.frame.maxY-5, width: 165+60, height: 15), tagsArray: tagss, textColor: UIColor.GP_Blue_Color, textFont: UIFont .systemFont(ofSize: 10), normalTagBackgroundColor: UIColor.backgroundColor, tagBorderColor: UIColor.GP_Blue_Color, contentInsets: UIEdgeInsets(top: 10, left: 5, bottom: 10, right: 5), labelContentInsets: UIEdgeInsets(top: 3, left: 3, bottom: 3, right: 3), labelHorizontalSpacing: 5, labelVerticalSpacing: 5)
                subBg.addSubview(tagsView!)
            }

            
        }
        
        self.view.bringSubviewToFront(self.slideMenuView)
        
         
        if pullBtn == nil {
            
            pullBtn = UIButton()
            pullBtn!.backgroundColor = UIColor.clear
            pullBtn!.setTitle("点击查看详情", for: .normal)
            pullBtn!.setTitleColor(UIColor.textPlaceHolderColor, for: .normal)
            pullBtn!.addTarget(self, action: #selector(pullClick), for: .touchUpInside)
            pullBtn!.titleLabel?.font = UIFont.smallFont
            bbg.addSubview(pullBtn!)
            let _ = pullBtn!.sd_layout()?.widthRatioToView(bbg,1)?.bottomSpaceToView(bbg,HT_TabbarSafeBottomMargin)?.heightIs(25)
            bbg.bringSubviewToFront(pullBtn!)
        }


        if self.isDayBtnClick == false {
            
            titScrView?.removeFromSuperview()
            titScrView = UIScrollView()
            titScrView?.showsHorizontalScrollIndicator = false
            titScrView?.tag = 1000
            bbg.addSubview(titScrView!)
            let  _ = titScrView?.sd_layout()?.leftSpaceToView(bbg,16)!.rightSpaceToView(bbg,45)!.topSpaceToView(bbg,5)!.heightIs(35)!
            
            titScrView!.updateLayout()
            if titsLine.count > 0{
                
                titsLine.removeAll()
            }

            
            for item in self.curDetailCategory!.routeInfoList! {
                
                titsLine.append(item.stepName!)
            }
            var stArr = [String]()
            for st in titsLine{
                
                let t = st.split(string: "-")[0]
                stArr.append(t)
            }
            var nowTitArr = [String]()
            nowTitArr.append("全部")
            for stt in stArr{
                
                if nowTitArr.contains(stt) == false{
                    
                    nowTitArr.append(stt)
                }
            }

            for index in 0 ..< nowTitArr.count{
                
                
                let tLab = UIButton()
                tLab.addTarget(self, action: #selector(dayBtnClick), for: .touchUpInside)
                tLab.tag = 100010+index
                tLab.frame = CGRect(x:index*50 , y: 5, width: 50, height: 24)
                tLab.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight(rawValue: 0.2))
                tLab.setTitleColor(UIColor.textTitleColor, for: .normal)
                tLab.setTitle(nowTitArr[index], for: .normal)
                tLab.backgroundColor = UIColor.white
                titScrView?.addSubview(tLab)
                tLab.layer.cornerRadius = 12
                tLab.layer.masksToBounds = true
                titScrView?.setupAutoContentSize(withRightView: tLab, rightMargin: 0)
                let bline = UIView()
                bline.tag = 8080
                bline.isHidden = true
                tLab.addSubview(bline)
                bline.backgroundColor = UIColor.GP_Orange_Color
                let _ = bline.sd_layout()?.widthIs(40)!.heightIs(1)!.centerXEqualToView(tLab)!.bottomSpaceToView(tLab,0)
                if  index == 0 && self.lastTitLab == nil{
                    
                    self.lastTitLab = tLab
                    tLab.backgroundColor = UIColor.init(hexString: "#fdf1e6")
                    tLab.setTitleColor(UIColor.init(hexString: "#f19058"), for: .normal)

                }
                if index == self.lastTitLab!.tag - 100010{
                    
                    tLab.backgroundColor = UIColor.init(hexString: "#fdf1e6")
                    tLab.setTitleColor(UIColor.init(hexString: "#f19058"), for: .normal)
                    
                    

                    
                    
                }
                
                
            }
        }
        
    }
    @objc func cardMaskClick(btn:UIButton){
        
        let mod = self.curSubCardArr.get(at: btn.tag-10086)
        
        
        self.openBtn?.isSelected = true
        UIView.animate(withDuration: 0.6, delay: 0, options: .curveEaseIn, animations: {
            
            self.slideMenuView.sd_x = KScreenWidth-45
            
            
        }) { (finish) in
                
            self.openBtn?.setImage(UIImage(named: "i_add"), for: .normal)
        }
        
        if mod!.isActivity == true{
            
            if mod!.pdtId != nil{
                
                //跳转到产品详情
                API.playDetail(params: ["id":mod!.pdtId!]) { (result) in
                    
                    API.productCommentList(params: ["page":"1",
                                                    "pdtId":mod!.pdtId!]) { (pageVo) in
                        
                                                        
                                                        let page = pageVo as! Page<CommentVo>
                                                        let dvc = ProductDetailVC()
                                                        dvc.product = (result as! ProductVo)
                                                        if page.list.count > 0{
                                                            
                                                            dvc.commentVo = page.list.first
                                                        }
                                                        PUSH(from: self, to: dvc)
                    }
                    

                }
            }else{
                
                ToastUtil.show(msg: "暂无产品详情")
            }

            
            return
            
        }
        
        
        API.home_category_detail(params: ["projectId":mod!.linkId!]) { (result) in
             
             
             let dvc = PlaceDetailVC()
             dvc.fromRoute = true
             dvc.cateVo = (result as! CategoryVo)
             PUSH(from: self, to: dvc)
             
         }
        
        
    }
    
    func showDetailView(){
        
        self.view.addSubview(self.detailView)
        self.detailView.frame = CGRect(x: 0, y: 0, width: KScreenWidth, height: KScreenHeight)
        let bgImgv = UIImageView()
        bgImgv.alpha = 0.5
        bgImgv.backgroundColor = UIColor.init(patternImage: UIImage(named: "paybg")!)
        detailView.addSubview(bgImgv)
        let _ = bgImgv.sd_layout()?.spaceToSuperView(.zero)
        
        let contBg  = UIView()
        contBg.backgroundColor = UIColor.white
        detailView.addSubview(contBg)
        contBg.frame = CGRect(x: 16, y: HT_StatusBarAndNavigationBarHeight+55, width: KScreenWidth-32, height: view.height-HT_StatusBarAndNavigationBarHeight-55-HT_TabbarSafeBottomMargin)
        contBg.SetMutiBorderRoundingCornersTLTR(contBg, corner: 20)
        
        let downBtn = UIButton()
        downBtn.addTarget(self, action: #selector(downBtnClick), for: .touchUpInside)
        contBg.addSubview(downBtn)
        downBtn.setImage(UIImage(named: "向下"), for: .normal)
        let _ = downBtn.sd_layout()?.leftSpaceToView(contBg,16)!.topSpaceToView(contBg,10)!.widthIs(45)!.heightIs(35)
    
        let tLab = UILabel()
        tLab.font = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight(rawValue: 0.2))
        tLab.text = self.curDetailCategory?.platfromProject?.proName
        tLab.textColor = UIColor.textTitleColorBlack
        contBg.addSubview(tLab)
        let _ = tLab.sd_layout()?.leftSpaceToView(contBg,10)!.rightSpaceToView(contBg,10)!.topSpaceToView(downBtn,5)!.heightIs(20)
        
        let webView = WKWebView()
        contBg.addSubview(webView)
        let _ = webView.sd_layout()?.leftSpaceToView(contBg,10)!.rightSpaceToView(contBg,10)!.topSpaceToView(tLab,16)!.bottomSpaceToView(contBg,45)
        webView.backgroundColor = UIColor.clear
        webView.isOpaque = false
        webView.scrollView.backgroundColor = UIColor.clear
        webView.scrollView.showsVerticalScrollIndicator = false
        webView.loadHTMLString(self.createHtml().resizeImageForHTML(), baseURL: nil)
        
        contBg.addSubview(self.commentBottomView)
        let _ = commentBottomView.sd_layout()?.widthRatioToView(contBg,1)!.heightIs(45)!.bottomSpaceToView(contBg,0)

    }
    

    func startSearch(){
        
        let searVC = PYSearchViewController.init(hotSearches: ["杭州2日小众路线","厦门2日游","西安经典3日游","苏州","上海"], searchBarPlaceholder: "请输入目的地、线路") { (vc, bar, str) in
            
            
            self.keywords = str!
            self.curCategory = nil
            vc?.dismiss(animated: true, completion: {
                
                self.categorys.removeAll()
                self.mPage = 1
                self.sendRequest()

            })
            
        }
        let nav = UINavigationController(rootViewController: searVC!)
        self.present(nav, animated: true) {
            
            
        }
    }
    
       func createHtml() -> String{
           
           var html = ""

           for item in self.curDetailCategory!.projectDetailList! {
               
               
               
               if item.type == "text"  {
                   
                let pNode = String(format: "<p style=\"text-align: justify; line-height: 1.5em;\"><span style=\"color: rgb(66, 66, 66); font-family: 宋体, SimSun;font-size:22px\">%@</span></p>", item.conUrl!.replacingOccurrences(of: "\n", with: "<br />"))
                   html += pNode


               }else if item.type == "img"{
                   

                   let imgNode = String(format: "</p><p style=\"text-align: justify; line-height: 2em;\"><img title=\"\" alt=\"\" src=\"%@\"/></p>", item.conUrl!)
    
                   html += imgNode
                   
               }else if item.type == "video"{
                   
                   let videoNode = String(format: "<video class=\"edui-upload-video  vjs-default-skin        video-js\" controls=\"\" preload=\"meta\" width=\"375\" height=\"280\" src=\"%@\"><source src=\"%@\" type=\"video/mp4\"/></video>", item.videoUrl!,item.videoUrl!)
                   html += videoNode

               }

           }
           return html
       }
    
    
    @objc func topMenuClick(btn:UIButton){
        
        
        self.lastTitLab = nil
        let mod = self.categorys.get(at:btn.tag-1990)
        self.curCategory = mod
        if self.isOnlyOne == false{
         
            self.sendRequestDetail()

        }
                
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight(rawValue: 0.2))
        

        if lastMenuBtn != btn {
            
            self.lastMenuBtn!.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight(rawValue: 0.2))
        }
        
        lastMenuBtn = btn
        bg.setContentOffset(CGPoint(x: 0, y: 0), animated: true)

        

  
    }
    
    @objc func openOrClose(btn:UIButton){
        
        if btn.isSelected == true {
            

            UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseIn, animations: {
                
                self.slideMenuView.sd_x = KScreenWidth-225

                
            }) { (finish) in
                   
                self.openBtn?.setImage(UIImage(named: "关闭"), for: .normal)

            }
            
        }else{
            

            
            UIView.animate(withDuration: 0.6, delay: 0, options: .curveEaseIn, animations: {
                
                self.slideMenuView.sd_x = KScreenWidth-45
                
                
            }) { (finish) in
                    
                self.openBtn?.setImage(UIImage(named: "i_add"), for: .normal)
            }
        }
        
        btn.isSelected.toggle()
        
    }
    
    @objc func pullClick(){
        
        if self.curCategory == nil{
            
            ToastUtil.showHUDError(msg: "暂无详情介绍")
            return 
        }
        
        self.showDetailView()

    }
    
    @objc func slideMenuClick(btn:UIButton){
        
        if btn.tag == 10087{
            
              if SPUtil.init().loginStatus == 0 {
                  
                  APP.backToVC = self
                  PUSH(from: self, to: LoginViewController())
                  return
              }
              if SPUtil.init().mobile.count == 0 {
                  
                  APP.backToVC = self
                  PUSH(from: self, to: BindPhoneVC())
                  return
            
              }
            
            API.collect(params: ["type":"COL",
                                 "colType":"ROUTE",
                                 "mobile":SPUtil.init().mobile!,
                                 "pdtId":self.curDetailCategory!.platfromProject!.id!]) { (result) in
                
                                    ToastUtil.show(msg: "收藏成功")
                
            }
            
        }else if btn.tag == 10089{
            
            let img0 = BZHttpFileHelper.imageWithScreenshot()
            let img1 = BZHttpFileHelper.compressImage(img0, toByte: 50*1024)

            let shareItems:Array = [img1 as Any] as [Any]
                    let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
            activityViewController.excludedActivityTypes = [UIActivity.ActivityType.print, UIActivity.ActivityType.postToWeibo, UIActivity.ActivityType.copyToPasteboard, UIActivity.ActivityType.addToReadingList, UIActivity.ActivityType.postToVimeo]
                    self.present(activityViewController, animated: true, completion: nil)
            
        }else if btn.tag == 10090{
            
            var actions: Array<PopoverAction> = [PopoverAction]()
             for item in ["境内租车","境外租车"] {
                 
                 let action = PopoverAction.init(title: item) { (action) in
                     
                     let vo = action?.model as! String
                    
                    if vo == "境内租车"{
                        
                        let web = WebViewController()
                        web.myTitle = "租车"
                        web.url = Constant.RENTCAR_URL
                        PUSH(from: self, to: web)
                        
                    }else{
                        
                        let web = WebViewController()
                        web.myTitle = "租车"
                        web.url = Constant.RENTCAR_FOREIGN_URL
                        PUSH(from: self, to: web)
                    }
                     
                     
                     
                 }
                 action?.model = item
                 actions.append(action!)
                 
             }
             let popView = PopoverView.init()
             popView.hideAfterTouchOutside = true
             popView.style = .default
            popView.showShade = true
            popView.show(to: btn, with: actions)
            
        }else if btn.tag == 10088{
            

            let zivc = CommentSampleVC()
            zivc.type = "line"
            zivc.pid = self.curDetailCategory?.platfromProject?.id
            
            self.present(EasyNavigationController(rootViewController: zivc), animated: true) {
                
            }
        }
        
        
    }
    
    @objc func downBtnClick(){
        
        
        self.detailView.removeFromSuperview()
        
    }
    @objc func imgClick(tap:UITapGestureRecognizer){
        
        let imgg = tap.view as! MyImgView
        let datas = JXNetworkingDataSource(photoLoader: JXKingfisherLoader(), numberOfItems: { () -> Int in
            return 1
        }, placeholder: { (num) -> UIImage? in
            
            return nil
            
        }) { (num) -> String? in
            
            if imgg.url?.starts(with: "http") == true {

                return imgg.url!

            }else{
                

                return "https://hqctv.oss-cn-beijing.aliyuncs.com/"+imgg.url!
            }
            
        }
        
        JXPhotoBrowser(dataSource: datas).show(pageIndex: 0)
        
    }
    
    @objc func shareClick(){
        
        
        let img0 = BZHttpFileHelper.imageWithScreenshot()
        let img1 = BZHttpFileHelper.compressImage(img0, toByte: 50*1024)

        let shareItems:Array = [img1 as Any] as [Any]
                let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
        activityViewController.excludedActivityTypes = [UIActivity.ActivityType.print, UIActivity.ActivityType.postToWeibo, UIActivity.ActivityType.copyToPasteboard, UIActivity.ActivityType.addToReadingList, UIActivity.ActivityType.postToVimeo]
                self.present(activityViewController, animated: true, completion: nil)

    }
    @objc func favBtnClick(btn:UIButton){
        
          if SPUtil.init().loginStatus == 0 {
              
              APP.backToVC = self
              PUSH(from: self, to: LoginViewController())
              return
          }
          if SPUtil.init().mobile.count == 0 {
              
              APP.backToVC = self
              PUSH(from: self, to: BindPhoneVC())
              return
        
          }
        
        API.collect(params: ["type":"COL",
                             "colType":"ROUTE",
                             "mobile":SPUtil.init().mobile!,
                             "pdtId":self.curDetailCategory!.platfromProject!.id!]) { (result) in
            
            
                                ToastUtil.show(msg: "收藏成功")
        }
        btn.isSelected.toggle()
        
    }
    
    @objc func lookZixun(){

        let zivc = CommentSampleVC()
        zivc.type = "line"
        zivc.pid = self.curDetailCategory?.platfromProject?.id
        
        self.present(EasyNavigationController(rootViewController: zivc), animated: true) {
            
        }
    }
        
    @objc func sendBtnClick(){
            
          if SPUtil.init().loginStatus == 0 {
              
              APP.backToVC = self
              PUSH(from: self, to: LoginViewController())
              return
          }
          if SPUtil.init().mobile.count == 0 {
              
              APP.backToVC = self
              PUSH(from: self, to: BindPhoneVC())
              return
        
          }
        
        if inputV.text.count == 0 {
            
            ToastUtil.showHUDWarn(msg: "随便写点什么吧")
            return
        }
        
        
        API.projectComment(params: [
            "pdtId":self.curDetailCategory!.platfromProject!.id!,
            "mobile":SPUtil.init().mobile!,
            "content":inputV.text!]) { (result) in
            
                                        ToastUtil.show(msg: "评论已提交")
                                        self.commentbg.removeFromSuperview()
                                        

        }

    }
    @objc func cancelBtnClick(){
            
        commentbg.removeFromSuperview()
    }

    @objc func showCommentAlert() {
            
        self.view.addSubview(commentbg)
        let _  = commentbg.sd_layout()?.spaceToSuperView(.zero)

        let bgImgv = UIImageView()
        bgImgv.alpha = 0.5
        bgImgv.backgroundColor = UIColor.init(patternImage: UIImage(named: "paybg")!)
        commentbg.addSubview(bgImgv)
        let _ = bgImgv.sd_layout()?.spaceToSuperView(.zero)
        
        let bg2 = UIView()
        bg2.backgroundColor = UIColor.white
        commentbg.addSubview(bg2)
        let _ = bg2.sd_layout()?.bottomSpaceToView(commentbg,0)?.widthRatioToView(commentbg,1)?.heightIs(166)
        
        bg2.addSubview(inputV)
        inputV.placeholder = "发表评论"
        inputV.sd_cornerRadius = 3
        inputV.font = UIFont.commonFontSmall
        inputV.textColor = UIColor.textTitleColorBlack
        let _ = inputV.sd_layout()?.leftSpaceToView(bg2,16)!.rightSpaceToView(bg2,16)!.heightIs(90)!.topSpaceToView(bg2,25)
        inputV.layer.borderColor = UIColor.textTitleColorBlack.cgColor
        inputV.layer.borderWidth = 0.5
        
        let sendBtn = UIButton()
        sendBtn.setTitle("发送", for: .normal)
        sendBtn.addTarget(self, action: #selector(sendBtnClick), for: .touchUpInside)
        sendBtn.setTitleColor(UIColor.btnMainColor, for: .normal)
        sendBtn.titleLabel?.font = UIFont.commonFontSmall
        bg2.addSubview(sendBtn)
        
        let _ = sendBtn.sd_layout()?.rightSpaceToView(bg2,16)!.heightIs(28)!.widthIs(38)!.topSpaceToView(inputV,5)
        
        let cancelBtn = UIButton()
        cancelBtn.setTitle("取消", for: .normal)
        cancelBtn.addTarget(self, action: #selector(cancelBtnClick), for: .touchUpInside)
        cancelBtn.setTitleColor(UIColor.GP_Red_Color, for: .normal)
        cancelBtn.titleLabel?.font = UIFont.commonFontSmall
        bg2.addSubview(cancelBtn)
        
        let _ = cancelBtn.sd_layout()?.leftSpaceToView(bg2,16)!.heightIs(28)!.widthIs(38)!.topSpaceToView(inputV,5)

            
        }
}

extension RouteViewController:MKMapViewDelegate,UIScrollViewDelegate,SPPageMenuDelegate{
    
    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        
        if annotation .isKind(of: LSListAnnotation.self) {
            
            let mod:RouteInfoVo = (annotation as! LSListAnnotation).model as! RouteInfoVo
            
            if mod.isActivity == false{
                
                let pointReuseIndetifier = "pointReuseIndetifier"
                var annotationView = mapview?.dequeueReusableAnnotationView(withIdentifier: pointReuseIndetifier)
                if annotationView == nil{
                    
                    annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIndetifier)
                    annotationView?.canShowCallout = false
                    

                }
                if mod.isSelect == false{
                 
                    annotationView?.image = BZHttpFileHelper.image(withTitle: mod.stepNum.description, fontSize: 12, img: UIImage(named: "map_def")!)
                }else{
                    
                    annotationView?.image = BZHttpFileHelper.image(withTitle: mod.stepNum.description, fontSize: 12, img: UIImage(named: "place_ed")!)
                }



                return annotationView
                
                
            }else{
                
                let pointReuseIndetifier = "pointReuseIndetifier11"
                var annotationView = mapview?.dequeueReusableAnnotationView(withIdentifier: pointReuseIndetifier)
                if annotationView == nil{
                    
                    annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: pointReuseIndetifier)
                    annotationView?.canShowCallout = false

                }
                let url = URL(string: mod.imgUrl!)
                
                let img = SDImageCache.shared.imageFromDiskCache(forKey: mod.imgUrl?.split(string: "/").last)
                if img == nil{
                    
                    
                    DispatchQueue.global().async {//并行、异步
                        
                        var image: UIImage?
                        do {
                             let data = try Data(contentsOf: url!)
                            image = UIImage(data: data)
                            SDImageCache.shared.store(image, imageData: data, forKey: mod.imgUrl?.split(string: "/").last, toDisk: true) {
                                
                            }

                         }catch let error as NSError {
                             print(error)
                            
                         }
                        DispatchQueue.main.async {//串行、异步
                            
                            annotationView?.image = image?.scaleTo(w: 50, h: 50)

                        }
                    }
                    
                }else{
                    
                    
                    annotationView?.image = img!.scaleTo(w: 50, h: 50)
                }
                
                return annotationView

            }
            

        }
        return nil
    }
    
    @objc func annDetailClick(){
        
 
        

        API.home_category_detail(params: ["projectId":self.curMod!.projId!]) { (result) in
             
             
             let dvc = PlaceDetailVC()
             dvc.cateVo = (result as! CategoryVo)
             PUSH(from: self, to: dvc)
             
         }
        
    }
    func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
        
        if overlay is MKPolyline {
            let polylineRenderer = MKPolylineRenderer(overlay: overlay)
            polylineRenderer.strokeColor = UIColor.GP_Orange_Color
            polylineRenderer.lineWidth = 3
            return polylineRenderer
        }
        return MKPolylineRenderer()
        
    }
    func mapView(_ mapView: MKMapView, regionWillChangeAnimated animated: Bool) {
        
        
        if self.isFirstIn == false{
            
            UIView.animate(withDuration: 0.6, delay: 0, options: .curveEaseIn, animations: {
                
                self.slideMenuView.sd_x = KScreenWidth-45
                
                
            }) { (finish) in
                    
                self.openBtn?.setImage(UIImage(named: "i_add"), for: .normal)
                self.openBtn?.isSelected = true
            }
            
        }

    }

    func showAntions(arr:Array<RouteInfoVo>){
        
        if self.currentArr.count > 0{
            
            self.mapview!.removeAnnotations(self.currentArr)
        }
        
        self.currentArr.removeAll()
        

        
        if self.firstMod == nil {
            
            self.firstMod = arr.first
            self.firstMod?.isSelect = true
            self.curMod = arr.first
        }
        
        for item in arr {
            
//            let latlongt = BZHttpFileHelper.gaodeToBD(withLat: Double(item.latitude!)!, longt: Double(item.longitude!)!)
//            let lat = latlongt.split(string: ",").first
//            let longt = latlongt.split(string: ",").last

            let ann = LSListAnnotation(coordinates: CLLocationCoordinate2D(latitude: Double(item.latitude!)!, longitude: Double(item.longitude!)!), title: item.stepName, subTitle: item.title)
            
            self.mapview?.addAnnotation(ann!)
            ann?.model = item
            
            if item.isActivity == false {
                
                self.currentArr.append(ann!)

            }
        }
        
        let firstAnn = self.currentArr.first
        
        let mod = arr.first
        if mod?.latitude != nil && mod?.longitude != nil && self.backToUserClick == false{
            
            let coordinate = firstAnn?.coordinate
            let region = MKCoordinateRegion(center: coordinate!, span:  MKCoordinateSpan(latitudeDelta:  1.118404*0.26, longitudeDelta: 1.131468*0.26))
            self.mapview?.setRegion(region, animated: false)
        }

    }
    func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
        
        if view.annotation is MKUserLocation{
            
            return
        }
        self.backToUserClick = false
        let ann = view.annotation as! LSListAnnotation
        
        let mod = ann.model as! RouteInfoVo
        
        if mod.isActivity == true{
            
            if mod.pdtId!.count > 0{
                
                //跳转到产品详情
                API.playDetail(params: ["id":mod.pdtId!]) { (result) in
                    
                    API.productCommentList(params: ["page":"1",
                                                    "pdtId":mod.pdtId!]) { (pageVo) in
                        
                                                        
                                                        let page = pageVo as! Page<CommentVo>
                                                        let dvc = ProductDetailVC()
                                                        dvc.product = (result as! ProductVo)
                                                        if page.list.count > 0{
                                                            
                                                            dvc.commentVo = page.list.first
                                                        }
                                                        PUSH(from: self, to: dvc)
                    }
                    

                }
            }else{
                
                ToastUtil.show(msg: "暂无产品详情")
            }
            
            
            return
        }
        
        
        for item in self.curSubCardArr{
            
            item.isSelect = false
            
        }
        

        mod.isSelect = true
        
        
        if mod.id == self.curMod!.id{
            
            
        }else{
            
            
            self.showAntions(arr: self.curSubCardArr)

        }

        let index = (self.curSubCardArr as NSArray).index(of: mod)


        let coordinate = CLLocationCoordinate2D(latitude: Double((mod.latitude)!)!, longitude: Double((mod.longitude)!)!)
        let region = MKCoordinateRegion(center: coordinate, span:  MKCoordinateSpan(latitudeDelta: 2.118404*0.01, longitudeDelta: 2.131468*0.01))
        self.mapview?.setRegion(region, animated: false)
        
        self.curMod = mod
        
        //scr 滚动
        bg.setContentOffset(CGPoint(x: CGFloat(index)*(KScreenWidth-40), y: 0), animated: true)
        
    
        
    }

    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
        
    if self.curSubCardArr.count == 0{
        
        return
    }
    
        let pagee  = scrollView.contentOffset.x/(scrollView.bounds.width)

        let mod = self.curSubCardArr.get(at: Int(round(pagee)))
        


        if mod == nil{
            
            return
        }
        self.curMod = mod

        if mod!.isActivity == false{
            
            for item in self.curSubCardArr {
                
                item.isSelect = false
                
            }
            mod?.isSelect = true
        }

        showAntions(arr: self.curSubCardArr)

        
        let coordinate = CLLocationCoordinate2D(latitude: Double((mod?.latitude)!)!, longitude: Double((mod?.longitude)!)!)
        let region = MKCoordinateRegion(center: coordinate, span:  MKCoordinateSpan(latitudeDelta: 2.118404*0.02, longitudeDelta: 2.131468*0.02))
        self.mapview?.setRegion(region, animated: false)
        

    }
    

    @objc func dayBtnClick(btn:UIButton){

        self.backToUserClick = false
        self.isRemoveTitleScrollView = false
        self.openBtn?.isSelected = true
        UIView.animate(withDuration: 0.6, delay: 0, options: .curveEaseIn, animations: {
            
            self.slideMenuView.sd_x = KScreenWidth-45
            
            
        }) { (finish) in
                
            self.openBtn?.setImage(UIImage(named: "i_add"), for: .normal)
        }
        
        
        btn.backgroundColor = UIColor.init(hexString: "#fdf1e6")
        btn.setTitleColor(UIColor.init(hexString: "#f19058"), for: .normal)
        btn.layer.cornerRadius = 12
        btn.layer.masksToBounds = true
        
        let title = btn.titleLabel?.text
        var arr = [RouteInfoVo]()

        for item in self.curSubCardArr{
            
            item.isSelect = false            
        }
        
        self.firstMod = nil

        
        if self.lastTitLab != btn{

            lastTitLab!.backgroundColor = UIColor.white
            lastTitLab!.setTitleColor(UIColor.textTitleColor, for: .normal)

        }
        
        self.lastTitLab = btn
        
        
        
        if self.ccLine != nil {
              
              self.mapview?.removeOverlay(self.ccLine!)
          }

        if title == "全部"{
            
            //添加活动产品
            var arr = self.curDetailCategory!.routeInfoList!
            for item in self.getActivisGoods(){
                
                let tempRouteInfo = RouteInfoVo()
                tempRouteInfo.isActivity = true
                tempRouteInfo.longitude = item.longitude
                tempRouteInfo.latitude = item.latitude
                tempRouteInfo.imgUrl = item.icon
                tempRouteInfo.title = item.title
                tempRouteInfo.address = item.context
                tempRouteInfo.pdtId = item.pdtId
                
                arr.append(tempRouteInfo)
                
                
            }
            
            self.isDayBtnClick = true
            self.reloadMapCards(arr: arr)
            self.showAntions(arr: arr)
            self.isDayBtnClick = false

            
            //画线

            self.points.removeAll()
  

            for item in self.curDetailCategory!.routeInfoList!{
                
//                let latlongt = BZHttpFileHelper.baiduToGaode(withLat: Double(item.latitude!)!, longt: Double(item.longitude!)!)
//                let lat = latlongt.split(string: ",").first
//                let longt = latlongt.split(string: ",").last
                
                let coordinate = CLLocationCoordinate2D(latitude: Double((item.latitude)!)!, longitude: Double((item.longitude)!)!)
                self.points.append(coordinate)

            }
            
            self.ccLine = MKPolyline.init(coordinates: self.points, count: self.points.count)
            
            self.mapview?.addOverlay(ccLine!, level: .aboveLabels)


        }else{
            
            
            for item in self.curDetailCategory!.routeInfoList! {
                //D13-58
                let sep = item.stepName?.split(string: "-").first
                if sep == title{
                    
                    arr.append(item)
                }
            }
            
            self.isDayBtnClick = true
            self.reloadMapCards(arr: arr)
            self.isDayBtnClick = false

            self.showAntions(arr: arr)
            
            //画线
            self.points.removeAll()


            for item in arr{
                
//                let latlongt = BZHttpFileHelper.baiduToGaode(withLat: Double(item.latitude!)!, longt: Double(item.longitude!)!)
//                let lat = latlongt.split(string: ",").first
//                let longt = latlongt.split(string: ",").last
                
                let coordinate = CLLocationCoordinate2D(latitude: Double((item.latitude)!)!, longitude: Double((item.longitude)!)!)
                self.points.append(coordinate)

            }
            self.ccLine = MKPolyline.init(coordinates: self.points, count: self.points.count)
            
            self.mapview?.addOverlay(ccLine!, level: .aboveLabels)
        }
        
            //scr 滚动
            bg.setContentOffset(CGPoint(x: 0*KScreenWidth, y: 0), animated: true)
            
    }
    
    
    @objc func backToUser(){
        
        let coordinate = CLLocationCoordinate2D(latitude: XMLocationManager.share()!.latitude,longitude: XMLocationManager.share()!.longitude )
        let region = MKCoordinateRegion(center: coordinate, span:  MKCoordinateSpan(latitudeDelta: 2.118404*0.1, longitudeDelta: 2.131468*0.1))
        self.mapview?.setRegion(region, animated: false)
        self.backToUserClick = true

    }
    
    @objc func backToLine(){
        
        let coordinate = CLLocationCoordinate2D(latitude: Double((self.curMod!.latitude)!)!, longitude: Double((self.curMod!.longitude)!)!)
        let region = MKCoordinateRegion(center: coordinate, span:  MKCoordinateSpan(latitudeDelta: 2.118404*0.1, longitudeDelta: 2.131468*0.1))
        
        self.mapview?.setRegion(region, animated: false)
    }
    
    func pageMenu(_ pageMenu: SPPageMenu, itemSelectedAt index: Int) {
        
        print(index.description)
        if index > 0  {
            
            self.backToUserClick = false

        }

        if self.isOnlyOne == false{

            self.lastTitLab = nil
            self.isRemoveTitleScrollView = true
            let mod = self.categorys.get(at: index)
            self.curCategory = mod
            self.sendRequestDetail()

        }
    }
}





